#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <string>
#include <stack>
#include <set>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
using namespace std;
typedef long long ll;

ll cnt[30];

int main()
{
    IOS;
    ll n;
    string s;
    cin>>n;
    while(n--){
        memset(cnt,0,sizeof(cnt));
        cin>>s;
        ll len=s.length();
        for(ll i=0;i<len;i++){
            cnt[s[i]-'a']++;
        }
        ll flag=0;
        for(ll i=0;i<26;i++){
            if(cnt[i]&1)flag++;
        }
        if(flag>1){
            cout<<"Impossible"<<endl;
            continue;
        }
        ll ans=0;
        for(ll l=0,r=len-1;l<r;l++,r--){
            if(s[l]==s[r])continue;
            ll index1=l+1,index2=r-1;
            for(;index1<r;index1++){
                if(s[index1]==s[r])break;
            }
            for(;index2>l;index2--){
                if(s[index2]==s[l])break;
            }
            if(index1-l<=r-index2){
                for(ll i=index1;i>l;i--){
                    s[i]=s[i-1];
                }
                s[l]=s[r];
                ans+=(index1-l);
            }
            else {
                for(ll i=index2;i<r;i++){
                    s[i]=s[i+1];
                }
                s[r]=s[l];
                ans+=(r-index2);
            }
        }
        cout<<ans<<endl;
    }
    getchar();
    getchar();
    return 0;
}
